package com.example.lawyerdemo.dongao.controller;

import com.example.lawyerdemo.dongao.entity.Lawyer;
import com.example.lawyerdemo.dongao.service.LawyerService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Classname LawyerController
 * @Description TODO
 * @Copyright:Copyright(c) 2021
 * @Company 英才汇硕信息科技有限公司
 * @Author zhang
 * @Version 1.0
 * @Date 2023/1/2 10:57
 */
@Controller
public class LawyerController {
    @Autowired
    LawyerService lawyerService;

    /**
     * 添加律师信息
     * @param lawyer
     * @return 成功失败
     */
    @RequestMapping("/addLawyer")
    public String addLawyer(Lawyer lawyer){
        lawyerService.addLawyer(lawyer);
        return "../static/success";
    }

    /**
     * 展示律师信息
     * @param model
     * @return 律师信息
     */
    @RequestMapping("/show")
    public  String showLawyer(Model model){
        List<Lawyer> lawyerList = lawyerService.findLawyer();
        model.addAttribute("lawyerList",lawyerList);
        return "../static/displayLawyer";
    }

    /**
     * 删除律师信息
     * @param lawyerid
     * @return 成功失败
     */
    @RequestMapping("/del")
    public String delLawyer(int lawyerid){
        lawyerService.removeLawyer(lawyerid);
        return "../static/displayLawyer";
    }
    @RequestMapping("/edit")
    public String getLawyerById(int lawyerid, Model model){
        Lawyer lawyerById = lawyerService.findLawyerById(lawyerid);
        model.addAttribute("lawyerById", lawyerById);
        return "../static/modifyLawyer";
    }
    @RequestMapping("/editLawyer")
    public String modifyLawyer(Lawyer lawyer){
        lawyerService.modifyLawyer(lawyer);
      return "redirect:/show";

    }
}
